﻿using Sai.Core;
using Sai.Core.Reporting;
using Sai.Test.TestDataBuilders;
using Sai.Test.XUnit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xunit;

namespace Sai.Test
{
    public class TypeListingByNamespaceFacts
    {
        public class OnSerialization
        {
            [Fact, InMemoryTest]
            public void Creates_MultiLine_Format()
            {
                List<IAssemblyDifference> diffs = new List<IAssemblyDifference>();
                diffs.Add(SimpleAssemblyDifferenceBuilder.Differences()
                    .Named("TestDiff")
                    .FromVersion("1")
                    .ToVersion("2")
                    .Add(TypeNameBuilder.Type().Named("Example1").InNamespace("Ex").Build())
                    .Add(TypeNameBuilder.Type().Named("Example2").InNamespace("Ex2").Build())
                    .Add(TypeNameBuilder.Type().Named("Example3").InNamespace("Ex2").Build())
                    .Add(TypeNameBuilder.Type().Named("Example4").InNamespace("Ex").Build())
                    .Build());

                var addedTypesFactory = new AddedTypesListingFactory();
                TypeListingByNamespace addedTypes = (TypeListingByNamespace)addedTypesFactory.Create(diffs);

                string output = ObjectFlattener<TypeListingByNamespace>.Flatten(addedTypes);

                Assert.Contains("Name=\"Added Types\"", output);
                Assert.Contains("<Namespaces>", output);
                Assert.Contains("<Namespace Name=\"Ex\">", output);
                Assert.Contains("<Namespace Name=\"Ex2\">", output);
                Assert.Contains("<Type Name=\"Example1\" Namespace=\"Ex\" FullName=\"Ex.Example1\" />", output);
                Assert.Contains("<Type Name=\"Example4\" Namespace=\"Ex\" FullName=\"Ex.Example4\" />", output);
                Assert.Contains("<Type Name=\"Example2\" Namespace=\"Ex2\" FullName=\"Ex2.Example2\" />", output);
                Assert.Contains("<Type Name=\"Example3\" Namespace=\"Ex2\" FullName=\"Ex2.Example3\" />", output);
                Assert.Contains("<Types>", output);
                Assert.Contains("</Types>", output);
                Assert.Contains("</Namespaces>", output);
            }
        }

    }
}
